<?php

function insert_link(
$p_link_url
, $p_link_name
) {
    mysql_query("
			INSERT INTO TB_LINK(
				LINK_URL
					,LINK_NAME
	
			)VALUES(
				'" . $p_link_url . "'
					,'" . $p_link_name . "'
	
			)	
		") or die(mysql_error());
    return mysql_insert_id();
}

function update_link(
$p_link_id
, $p_link_url
, $p_link_name
) {
    mysql_query("
			UPDATE TB_LINK 
			SET
				LINK_URL='" . $p_link_url . "'
					,LINK_NAME='" . $p_link_name . "'
	
			WHERE LINK_ID =  '" . $p_link_id . "'
		");
}

function get_all_link($p_where_clause, $p_offset, $p_num_row, $p_order_by=" LINK_ID DESC ") {
    $rs = mysql_query("
		SELECT 
			LINK_ID
				,LINK_URL
				,LINK_NAME

		FROM TB_LINK	
		WHERE 1 " . $p_where_clause . "		
		ORDER BY " . $p_order_by . "
		LIMIT " . $p_offset . "," . $p_num_row . "
		") or die(mysql_error());
    return $rs;
}

function get_singer_link($p_link_id) {
    $rs = mysql_query("
		SELECT 
			LINK_ID
				,LINK_URL
				,LINK_NAME

		FROM TB_LINK	
		WHERE LINK_ID =  '" . $p_link_id . "'		
		") or die(mysql_error());
    return $rs;
}

function draw_link_option($p_link_url) {
    $v_opt = '';
    $rs = mysql_query("SELECT LINK_URL, LINK_NAME  FROM TB_LINK ") or die(mysql_error());
    while ($arr = mysql_fetch_array($rs, MYSQL_NUM)) {
        if ($arr[0] == $p_link_url)
            $v_opt .= "<option selected value ='" . $arr[0] . "'>" . $arr[1] . "</option>";
        else
            $v_opt .= "<option value ='" . $arr[0] . "'>" . $arr[1] . "</option>";
    }
    return $v_opt;
}

?>
